package com.xiaoxu.intranetweb.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.SysRoleInfoFunctionWeb;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ISysRoleInfoFunctionWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.text.html.Option;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Component
public class WebFunctionUtil {

    @Autowired
    private ISysRoleInfoFunctionWebService iSysRoleInfoFunctionWebService;

    public Map webFunction(Map userPermissionWeb, String name) {
        Map result = new HashMap<>();
        result.put("code", 1);
        Object o = userPermissionWeb.get(name);//null
        boolean b = userPermissionWeb.containsKey(name);//false
        //o是1

//        if (userPermissionWeb.get(name) != null|| !userPermissionWeb.get(name).equals("0")) {
//            result.put("code", 0);
//            result.put("msg", "该功能暂未开放");
//        }

        if (o != null) {
            if (Integer.parseInt(o.toString()) == 1) {
                result.put("code", 0);
                result.put("msg", "该功能暂未开放");
                return result;
            }
        }

//        if (o == null&&) {
//            result.put("code", 0);
//            result.put("msg", "该功能暂未开放");
//            return result;
//        }
//        System.out.println("userPermissionWeb11111:"+name);
        if (!userPermissionWeb.containsKey(name)) {
            QueryWrapper<SysRoleInfoFunctionWeb> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("WEB_FUNCTION_NAME", name);
            SysRoleInfoFunctionWeb sysRoleInfoFunctionWeb = iSysRoleInfoFunctionWebService.getOne(queryWrapper1);
            result.put("code", 0);
            result.put("msg", "您没有" + sysRoleInfoFunctionWeb.getWebFunctionExplain() + "的权限");
            return result;
        }

//        if (o != null) {
//            if (o.equals("1")) {
//                result.put("code", 0);
//                result.put("msg", "该功能暂未开放");
//                return result;
//            }
//        }

        return result;
    }


}
